package com.feng.aop.aspects;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
public class LogAspects {

    @Pointcut("execution(* com.feng.aop.pojo.MathCalculator.*(..))")
    public void pointCut(){ }

    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint){
        //获取参数
        Object[] args = joinPoint.getArgs();
        //获取方法名
        String name = joinPoint.getSignature().getName();
        System.out.println("除法"+name+"运行。。。参数列表是:{"+ Arrays.asList(args)+"}");
    }


    @AfterReturning(value = "pointCut()",returning ="result" )
    public void logReturn(JoinPoint joinPoint,int result){
        System.out.println(""+joinPoint.getSignature().getName()+"结果正常返回   结果为"+result+"");
    }



    @AfterThrowing(value = "pointCut()",throwing ="exception" )
    public void logException(JoinPoint joinPoint,Exception exception){
        System.out.println("除法异常异常信息为 "+exception);
    }

    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint){
        System.out.println("除法"+joinPoint.getSignature().getName()+"运行结束");
    }
}
